$(function(){
	var basePath=$("#basepath").val();
	$(".project_auth_desc_show").click(function(){
		var desc=$(this).find(".description_div").html();
		$("#project_auth_description_box .modal-body").html(desc);
	});	
	$(".project_auth_fail").click(function(){
		$("#project_auth_fail_reason_box textarea").val("");
		var prjId=$(this).parent().parent().find("td input[name='choose']").val();
		$("#project_auth_fail_reason_box input[name='prjId']").val(prjId);
		$("#project_auth_fail_reason_box_alert_container").html("");
	});
	$("#project_auth_fail_reason_box_confirm").click(function(){
		var prjId=$("#project_auth_fail_reason_box input[name='prjId']").val();
		var failReason=$("#project_auth_fail_reason_box textarea").val();
		if(failReason==null||failReason==""){
			makeAlert("请输入审核不通过原因","error",$("#project_auth_fail_reason_box_alert_container"),"no_reason");
			return;
		}else{
			$("#project_auth_fail_reason_box_alert_container .no_reason").alert('close');
		}
		$.post(basePath+ "admin/project/failProject/"+prjId,
				{failReason:failReason},
				function(data,textStatus){
					if(textStatus=="success"){
						switch (data) {
						case "-1":
							alert("请勿进行非法操作");
							window.location=basePath;
							break;
						case "-2":
							alert("参数错误,请重试");
							history.go(0);
							break;
						case "0":
							noty({text:"更新成功,正在刷新"});
							history.go(0);
							break;
						default:
							alert("登陆状态已过期,请重新登陆");
							window.location=basePath;
							break;
						}
					}
			}, "text");
	});
	$(".project_auth_pass").click(function(){
		var prjId=$(this).parent().parent().find("td input[name='choose']").val();
		$.post(basePath+ "admin/project/passProject",
				{"prjIdList[]":prjId},
				function(data,textStatus){
					if(textStatus=="success"){
						switch (data) {
						case "-1":
							alert("请勿进行非法操作");
							window.location=basePath;
							break;
						case "0":
							noty({text:"更新成功,正在刷新"});
							history.go(0);
							break;
						default:
							alert("登陆状态已过期,请重新登陆");
							window.location=basePath;
							break;
						}
					}
			}, "text");
	});
	$("#project_auth_muti_pass").click(function(){
		var prjIdList=$("#project_auth_list_table input[name=choose]:checked");
		if(prjIdList.length==0){
			noty({text:"请至少选择一个题目"});
			return;
		}
		var prjListArr=new Array();
		for(i=0;i<prjIdList.length;i++){
			prjListArr[i]=$(prjIdList[i]).val();
		}
		$.post(basePath+ "admin/project/passProject",
				{"prjIdList":prjListArr},
				function(data,textStatus){
					if(textStatus=="success"){
						switch (data) {
						case "-1":
							alert("请勿进行非法操作");
							window.location=basePath;
							break;
						case "0":
							noty({text:"更新成功,正在刷新"});
							history.go(0);
							break;
						default:
							alert("登陆状态已过期,请重新登陆");
							window.location=basePath;
							break;
						}
					}
			}, "text");
	});
	$("#project_auth_select_all").click(function(){
		   $("input[type='checkbox']").prop("checked",true);
	});
	$("#project_auth_select_no").click(function(){
		   $("input[type='checkbox']").prop("checked",false);
	});
});